/*
* @Author: chenggh
* @Date: 2025-06-21
* @Link to Problem : https://webvpn.neu.edu.cn/https/62304135386136393339346365373340bfebea318fd008d8f60d257088/courses/27/part/223/problem/1008
*/
#include <iostream>
#include <vector>
#define int long long
using namespace std;
// 能不能在最大上限x之下分成k组
vector<int> a;
bool check(int x,int k){
	int sum = 0, heap = 0;
	for(int i = 0; i < a.size(); i++){
		if(a[i] > x) return false;

		if(sum + a[i] <= x){
			sum += a[i];
		}else{
			heap += 1;
			if(heap == k) return false;
			sum = a[i];
		}
	}
	return true;
}
int32_t main(){
	int n, k;
	cin >> n >> k;
	a.resize(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	// 二分
	long long l = 1, r = 1e15;
	while(l < r){
		long long mid = (r - l) / 2 + l;
		if(!check(mid, k)) l = mid + 1;
		else r = mid;
	}
	cout << l << endl;
	return 0;
}